package com.smzd.projforge.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smzd.core.business.AbstractService;
import com.smzd.core.dao.IDao;
import com.smzd.core.utils.json.FGRowConverter;
import com.smzd.projforge.dao.MTMRelationDao;
import com.smzd.projforge.domain.MTMRelation;

@Service
public class MTMRelationService extends AbstractService<MTMRelation> {
	@Autowired
	private MTMRelationDao dao;

	@Override
	protected IDao<MTMRelation> getDao() {
		return dao;
	}

	@Override
	protected FGRowConverter<MTMRelation> getConverter() {
		return ConverterHolder.converter;
	}

	static class ConverterHolder {
		static final FGRowConverter<MTMRelation> converter = new FGRowConverter<MTMRelation>() {
			@Override
			public Object[] convert(MTMRelation elem) {
				Object[] fs = new Object[] { 
						elem.getId(),
						AbstractService.getObjectByField(elem.getMaster()),
						AbstractService.getObjectByField(elem.getSlave()),
						AbstractService.getObjectByField(elem.getRelation()),
						AbstractService.getObjectByField(elem.getMasterField()),
						AbstractService.getObjectByField(elem.getSlaveField()),
						elem.getType()
				};
				return fs;
			}
		};
	}
	
	public void insertByMSClasses(MTMRelation relation){
		dao.insertByMSClasses(relation);
	}
	public void insertByMSFields(MTMRelation relation){
		dao.insertByMSFields(relation);
	}
}
